package com.jindianjichi.subject.domain.handler.subject;

import com.jindianjichi.basic.entity.SubjectBrief;
import com.jindianjichi.basic.service.SubjectBriefService;
import com.jindianjichi.subject.common.enums.IsDeletedEnum;
import com.jindianjichi.subject.common.enums.SubjectInfoTypeEnum;
import com.jindianjichi.subject.domain.entity.SubjectInfoBo;
import com.jindianjichi.subject.domain.entity.SubjectOptionBo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class SubjectBriefHandler implements SubjectInfoHandler{
    @Resource
    SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBo.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBo.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBo queryById(Long subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBo subjectOptionBO = new SubjectOptionBo();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;

    }

}
